package com.hzit.controller;

import java.util.Collection;

import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.interceptor.ServletRequestAware;

import com.hzit.entity.User;
import com.hzit.utils.UserUtils;

public class UserAction/* implements ServletRequestAware*/{
	private Collection<User> users;
	private User user;
	
	public User getUser() {
		return user;
	}
	public void setUser(User user) {
		this.user = user;
	}
	public Collection<User> getUsers() {
		return users;
	}
	public void setUsers(Collection<User> users) {
		this.users = users;
	}

	public String queryAll(){
		users=UserUtils.getAll();
		return "queryAll_ok";	
	}
	public String delete(){
		UserUtils.deleteById(user.getId());
		return "queryAll";
	}
	public String queryUserById(){
		user=UserUtils.getById(user.getId());
		return "queryUserById_ok";
	}
	public String saveOrUpdate(){
		UserUtils.saveOrUpdate(user);
		return "queryAll";
	}
/*	private HttpServletRequest request;
	
	public String getAll(){
		Collection<User> user=UserUtils.getAll();
		request.setAttribute("users", user);
		return "getAll_ok";
	}
	public String delete(){
		String idStr = request.getParameter("id");
		int id = Integer.parseInt(idStr);
		UserUtils.deleteById(id);
		return "getAll";
	}
	public String getUserById(){
		String idStr=request.getParameter("id");
		int id =Integer.parseInt(idStr);
		User user=UserUtils.getById(id);
		request.setAttribute("user", user);
		return "getUserById_ok";
	}
	public String saveOrUpdate(){
		String idStr=request.getParameter("id");
		int id=Integer.parseInt(idStr);
		String name=request.getParameter("name");
		String ageStr=request.getParameter("age");
		int age=Integer.parseInt(ageStr);
		User user=new User(id,name,age);
		UserUtils.saveOrUpdate(user);
		return "getAll";
	}
	
	
	
	
	
	@Override
	public void setServletRequest(HttpServletRequest arg0) {
		// TODO Auto-generated method stub
		request=arg0;
	}*/
}
